package concurrency.chapter1;

import java.util.concurrent.TimeUnit;

/**
 * FileName: InterruptDemo2
 * Author:   周壮
 * Date:     2020/5/18 7:51
 * Description:
 */
public class InterruptDemo2 {

    public static void
    main(String[] args) throws
            InterruptedException {
        Thread thread = new
                Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("before:" + Thread.currentThread().isInterrupted());
                    Thread.interrupted(); //对线程进行复位，由 true 变成 false
                    System.out.println("after:" + Thread
                            .currentThread().isInterrupted());
                }
            }
        }, "interruptDemo");
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread.interrupt();
    }
}
